
package edu.depaul.se.courseregistration.jpa.courses;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

/**
 *
 * @author lmarco
 */
@NamedQueries({
    @NamedQuery(name=  College.COLLEGE_QUERY_ALL,query="select c from College c"),
    @NamedQuery(name = College.COLLEGE_QUERY_BY_ID, query = "SELECT c FROM College c WHERE c.collegeId = :" + College.COLLEGE_ID_PARAMETER_NAME), //Find subject By ID.
    @NamedQuery(name = College.COLLEGE_QUERY_BY_SHORTNAME, query = "SELECT c FROM College c WHERE c.collegeShortName = :" + College.COLLEGE_SHORTNAME_PARAMETER_NAME) //Find subject By ShortName.

})
@Entity
@Table(name = "COLLEGE")
@XmlRootElement
public class College implements Serializable {
    
    private static final long serialVersionUID = 1L;
    public static final String COLLEGE_QUERY_ALL = "College.findAll";
    public static final String COLLEGE_QUERY_BY_ID = "College.findById";
    public static final String COLLEGE_ID_PARAMETER_NAME = "collegeId";
    public static final String COLLEGE_QUERY_BY_SHORTNAME = "College.findByShortName";
    public static final String COLLEGE_SHORTNAME_PARAMETER_NAME = "collegeShortName";
    
    @Id
    @Column(name = "COLLEGE_ID")
    private Integer collegeId;
    @Column(name = "COLLEGE_SHORT_NAME")
    private String collegeShortName;
    @Column(name = "COLLEGE_NAME")
    private String collegeName;
    
    @OneToMany(cascade = CascadeType.ALL, 
                mappedBy = "collegeId", 
                fetch= FetchType.EAGER)
    private List<Subject> subjectList;
    @XmlElement(name="subjectList")
    public List<Subject> getSubjectList() {
        return subjectList;
    }

    public void setSubjectList(List<Subject> subjectList) {
        this.subjectList = subjectList;
    }

    public String getCollegeName() {
        return collegeName;
    }

    public void setCollegeName(String collegeName) {
        this.collegeName = collegeName;
    }

    public String getCollegeShortName() {
        return collegeShortName;
    }

    public void setCollegeShortName(String collegeShortName) {
        this.collegeShortName = collegeShortName;
    }
    
    public Integer getCollegeId() {
        return collegeId;
    }

    public void setCollegeId(Integer collegeId) {
        this.collegeId = collegeId;
    }


    @Override
    public int hashCode() {
        int hash = 0;
        hash += (collegeId != null ? collegeId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof College)) {
            return false;
        }
        College other = (College) object;
        if ((this.collegeId == null && other.collegeId != null) || (this.collegeId != null && !this.collegeId.equals(other.collegeId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("\n");
        sb.append("[ collegeId=").append(collegeId).append(" ]");
        return sb.toString();    }
    
}
